package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.setupweightlimitedvo.SetupWeightLimitedCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.setupweightlimitedvo.SetupWeightLimitedPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.setupweightlimitedvo.SetupWeightLimitedRespVO;
import com.cmc.cloud.cmclink.doc.vo.setupweightlimitedvo.SetupWeightLimitedUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.SetupWeightLimitedDO;
import com.cmc.cloud.cmclink.doc.service.SetupWeightLimitedService;


/**
 * 限重维护前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 限重维护")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/weightLimited")
public class SetupWeightLimitedController {

    @Resource
    private SetupWeightLimitedService setupWeightLimitedService;

    @Operation(summary = "创建限重维护")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission({'doc:setupWeightLimited:add','doc:setupWeightLimited:copy'})")
    public CommonResult<Void> createSetupWeightLimited(@Valid @RequestBody SetupWeightLimitedCreateReqVO createReqVO) {
        setupWeightLimitedService.createSetupWeightLimited(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新限重维护")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:setupWeightLimited:edit')")
    public CommonResult<Void> updateSetupWeightLimited(@Valid @RequestBody SetupWeightLimitedUpdateReqVO updateReqVO) {
        setupWeightLimitedService.updateSetupWeightLimited(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除限重维护")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('doc:setupWeightLimited:delete')")
    public CommonResult<Void> deleteSetupWeightLimited(@PathVariable("id") Long id) {
        setupWeightLimitedService.deleteSetupWeightLimited(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得限重维护")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<SetupWeightLimitedRespVO> getSetupWeightLimited(@PathVariable("id") Long id) {
        SetupWeightLimitedDO setupWeightLimited = setupWeightLimitedService.getSetupWeightLimited(id);
        return CommonResult.success(BeanUtil.copyProperties(setupWeightLimited, SetupWeightLimitedRespVO.class));
    }

    @Operation(summary = "获得限重维护列表")
    @GetMapping("/listAll")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<SetupWeightLimitedRespVO>> getSetupWeightLimitedList(@RequestParam("ids") Collection<Long> ids) {
        List<SetupWeightLimitedDO> list = setupWeightLimitedService.getSetupWeightLimitedList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, SetupWeightLimitedRespVO.class));
    }

    @Operation(summary = "获得限重维护分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:setupWeightLimited:search')")
    public CommonResult<PageResult<SetupWeightLimitedRespVO>> getSetupWeightLimitedPage(@Valid @RequestBody SetupWeightLimitedPageReqVO pageVO) {
        PageResult<SetupWeightLimitedDO> pageResult = setupWeightLimitedService.getSetupWeightLimitedPage(pageVO);
        List<SetupWeightLimitedRespVO> results = BeanUtil.copyToList(pageResult.getList(), SetupWeightLimitedRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
